let stu = require('../Dao/mongse');

//学生的业务层
module.exports = {
    //分页查询学生信息
    async getStudentInfoByPage(curPage, pageSize) {
        //分页对象
        let pageBean = {};
        //获得要显示的数据
        let datas = await stu.getuser(curPage, pageSize);
        //获得总条数
        let tolNum = await stu.getTolNum();
        //计算总页数
        let tolPage = Math.ceil(tolNum / pageSize);
        //开始封装分页对象
        pageBean = { datas, curPage, pageSize, tolNum, tolPage }
        //返回分页对象
        return pageBean;
    },


    //添加学生
    async stuAdd({ name, age, gender, address }) {
        let result = await stu.insertUser({ name, age, gender, address });
        return result;
    },

    //删除学生
    async stuDelete({ _id }) {
        let result = await stu.remove({ _id });
        return result;
    },

    //批量删除删除学生
    async stuRem(arr) {
        let result = await stu.deletions(arr);
        return result;
    },

    //修改学生
    async stuUpdata(stuid, stuObj) {
        let result = await stu.updateStu(stuid, stuObj);
        return result;
    },

    //查询学生详细信息
    async stuChaXiang(stuid) {
        return await stu.updateStu(stuid);
    },


    //查询学生信息
    async querys(obj) {
        return await stu.stuTypes(obj);
    }

}